Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports AllegNet
Imports Res = Ex03_ShowingText

Namespace Ex03_ShowingText
	Friend Class Main
		Inherits Api
		#Region "Properties"
		Private _Str_ScreenResolution As String = ""
		Private _Str_GfxMode As String = ""
		Private _Str_RenderingMode As String = ""
		Private _Str_BmpType As String = ""

		Public Property Str_ScreenResolution() As String
			Get
				Return _Str_ScreenResolution
			End Get
			Set
				_Str_ScreenResolution = Value
			End Set
		End Property
		Public Property Str_GfxMode() As String
			Get
				Return _Str_GfxMode
			End Get
			Set
				_Str_GfxMode = Value
			End Set
		End Property
		Public Property Str_RenderingMode() As String
			Get
				Return _Str_RenderingMode
			End Get
			Set
				_Str_RenderingMode = Value
			End Set
		End Property
		Public Property Str_BmpType() As String
			Get
				Return _Str_BmpType
			End Get
			Set
				_Str_BmpType = Value
			End Set
		End Property
		#End Region

		Friend Shared Fps As Integer = 0
		Friend Shared FpsToShow As Integer = 0

		Public Sub WinMain()
			Dim ScreenRes As ScreenResolution = ScreenResolution.Size_320_240
			Dim GfxMode As GfxModes = GfxModes.GfxAutoDetect
			Dim RenderingMode As RenderingModes = RenderingModes.Null
			Dim BmpTyp As BmpType = BmpType.Null


'			#Region "Get Params"
'			#Region "switch (Str_ScreenResolution)"
			Select Case Str_ScreenResolution
				Case "320 x 240"
					ScreenRes = ScreenResolution.Size_320_240
				Case "640 x 480"
					ScreenRes = ScreenResolution.Size_640_480
				Case "800 x 600"
					ScreenRes = ScreenResolution.Size_800_600
				Case "1024 x 768"
					ScreenRes = ScreenResolution.Size_1024_768
				Case "1088 x 612"
					ScreenRes = ScreenResolution.Size_1088_612
				Case "1152 x 864"
					ScreenRes = ScreenResolution.Size_1152_864
				Case "1280 x 720"
					ScreenRes = ScreenResolution.Size_1280_720
				Case "1280 x 768"
					ScreenRes = ScreenResolution.Size_1280_768
				Case "1280 x 800"
					ScreenRes = ScreenResolution.Size_1280_800
				Case "1280 x 960"
					ScreenRes = ScreenResolution.Size_1280_960
				Case "1280 x 1024"
					ScreenRes = ScreenResolution.Size_1280_1024
			End Select
'			#End Region

'			#Region " switch (Str_GfxMode)"
			Select Case Str_GfxMode
				Case "GfxAutoDetect"
					GfxMode = GfxModes.GfxAutoDetect
				Case "GfxAutoDetectFullScreen"
					GfxMode = GfxModes.GfxAutoDetectFullScreen
				Case "GfxAutoDetectWindowed"
					GfxMode = GfxModes.GfxAutoDetectWindowed
				Case "GfxDirectXAccel"
					GfxMode = GfxModes.GfxDirectXAccel
				Case "GfxDirectXWin"
					GfxMode = GfxModes.GfxDirectXWin
				Case "GfxDirectX"
					GfxMode = GfxModes.GfxDirectX
				Case "GfxDirectXSafe"
					GfxMode = GfxModes.GfxDirectXSafe
				Case "GfxDirectXSoft"
					GfxMode = GfxModes.GfxDirectXSoft
				Case "GfxDirectXOlv"
					GfxMode = GfxModes.GfxDirectXOlv
				Case "GfxGDI"
					GfxMode = GfxModes.GfxGDI
			End Select
'			#End Region

'			#Region "switch (Str_RenderingMode)"
			Select Case Str_RenderingMode
				Case "DoubleBuffering"
					RenderingMode = RenderingModes.DoubleBuffering
				Case "TripleBuffering"
					RenderingMode = RenderingModes.TripleBuffering
				Case "PageFlipping"
					RenderingMode = RenderingModes.PageFlipping

			End Select
'			#End Region

'			#Region "switch (Str_BmpType)"
			Select Case Str_BmpType
				Case "Memory"
					BmpTyp = BmpType.Memory
				Case "System"
					BmpTyp = BmpType.System
				Case "Video"
					BmpTyp = BmpType.Video

			End Select
'			#End Region
'			#End Region

			'Initialize AllegNet
			AllegNetInit()

			'Install Keyboard
			InstallKeyboard()

			'Install Timer
			InstallTimer()

			InstallMouse()

			'Set the application running on background
			SetDisplaySwitchMode(SwitchModes.SwitchBackground)

			'Set the render mode
			SetRenderMode(RenderingMode, BmpTyp)

			'Set the colorDepth
			SetColorDepth(CDepth.Depth_32_Bits) '32 Bits cause only this mode can accept ARGB

			'Set the Gfx Mode
			SetGfxMode(GfxMode, ScreenRes)

			'Declare a callback delegate to use with timer
			Dim cTimerFct As Cproc = New Cproc(AddressOf TimerFct)

			'Install cTimerFct to be calledback each 1000 ms (1 second)
			InstallInt(cTimerFct, 1000)

			'Initialize main loop condition
			Dim Done As Boolean = False

			'Instanciate a NetFont
			Dim NFontA As NetFont = LoadFontFromInstalledTTF("Informal Roman", 12,System.Drawing.Brushes.White)
			Dim NFontC As NetFont = LoadFontFromInstalledTTF("Times", 12, System.Drawing.Brushes.White)

			'Main Loop
			Do While Not Done
				'Acquire the Buffer
				AcquireBitmap(BufferedScreen)
				'Clear the buffer
				ClearBitmap(BufferedScreen)


				'
				 '*In allegnet there is 2 ways to draw text on teh screen
				 '*The first is to use Old Native Allegro Font and TextOut function
				 '
				TextOutEx(BufferedScreen, DefaultFont, "Frames per second : " & FpsToShow.ToString(), 10, 10, MakeCol(255, 255, 255), 0)

				'
				 '*The second is to use AllegNEt Font and functions
				 '*But AllegNEt font are not yet optimized, so use it carefully, and
				 '* never load a NetFont inside a loop or you will loose Fps dramaticly
								 '
				WriteTextToBmp(NFontA, BufferedScreen, "The Text", 10, 50)
				WriteTextToBmp(NFontC, BufferedScreen, "Another Text", 10, 100)


				'Release the Buffer
				ReleaseBitmap(BufferedScreen)

				'Render to screen with actual render settings
				ApiRenderer.Render()

				'Check for KeyPressed
				If KbKey(AllKeys.Esc) Then
					Done = True
				End If
				Fps += 1
			Loop
			'Exit AllegNet
			UninstallAllegNet()
		End Sub

		''' <summary>
		''' Timer function
		''' </summary>
		Private Sub TimerFct()
			FpsToShow = Fps
			Fps = 0
		End Sub
	End Class
End Namespace
